#include "server.hpp"

#define HOST "127.0.0.1"
#define PORT 3306
#define USER "root"
#define PASS "a2297554105"
#define DBNAME "gobang"

void log_test()
{
    //LOG(1, "%s-%d\n", "hellow world", 200);
    INF_LOG("你");
    DBG_LOG("好");
    ERR_LOG("啊");
}
void mysql_test()
{
    MYSQL* mysql = mysql_util::mysql_create(HOST, USER, PASS, DBNAME, PORT);
    mysql_util::mysql_destroy(mysql);
}
void json_test()
{
    Json::Value root;
    std::string tmp;
    root["姓名"] = "小明";
    root["年龄"] = 18;
    root["成绩"].append(98);
    root["成绩"].append(98.5);
    root["成绩"].append(98.8);
    json_util::serialize(root, tmp);
    DBG_LOG("%s", tmp.c_str());

    Json::Value value;
    json_util::unserialize(tmp, value);
    std::cout << "姓名: " << value["姓名"].asString() << std::endl;
    std::cout << "年龄: " << value["年龄"].asInt() << std::endl;
    int sz = value["成绩"].size();
    for(int i = 0; i < sz; i++)
    {
        std::cout << "成绩: " << value["成绩"][i].asFloat() << std::endl;
    }
}
void string_test()
{
    std::string str = "12,,,,12,31,23";
    std::vector<std::string> arry;
    string_util::split(str, ",", arry);
    for(auto e : arry)
    {
        DBG_LOG("%s", e.c_str());
    }
}
void file_test()
{
    std:: string filename = "./makefile";
    std::string body;
    file_util::read(filename, body);
    DBG_LOG("%s", body.c_str());
}
void db_test()
{
    user_table ut(HOST, USER, PASS, DBNAME, PORT);
    Json::Value user;
    user["username"] = "小明";
    //user["password"] = "123123";
    bool ret = ut.insert(user);
    //std::string body;
    //json_util::serialize(user, body);
    //DBG_LOG("%s", body.c_str());
    //std::cout << body << std::endl;
}
void online_test()
{
    online_manager om;
    wsserver_t::connection_ptr conn;
    uint64_t uid = 1;
    om.enter_game_hall(uid, conn);
    if(om.is_in_game_hall(uid))
    {
        DBG_LOG("IN GAME HALL");
    }
    else
    {
        DBG_LOG("NOT IN GAME HALL");
    }
    om.exit_game_hall(uid);
    if(om.is_in_game_hall(uid))
    {
        DBG_LOG("IN GAME HALL");
    }
    else
    {
        DBG_LOG("NOT IN GAME HALL");
    }
}

void room_test()
{
    user_table ut(HOST, USER, PASS, DBNAME, PORT);
    online_manager om;
    room_manager rm(&ut, &om);
    room_ptr rp = rm.create_room(10, 20);
    matcher mc(&rm, &ut, &om);
}
int main()
{
    gobang_server _server(HOST, USER, PASS, DBNAME, PORT);
    _server.start(8080);
    return 0;
}